package com.sinder.campus_prophet.web.jwgl;

import cc.lyceum.api.thxy.jwgl.ThxyJwgl;
import com.sinder.campus_prophet.core.annotation.RequestLimit;
import com.sinder.campus_prophet.core.global.ResponseMessage;
import com.sinder.campus_prophet.service.jwgl.TbJwglExamService;
import com.sinder.campus_prophet.service.jwgl.TbJwglInfoService;
import com.sinder.campus_prophet.service.jwgl.bean.dto.MyExamSynDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotBlank;

/**
 * 考试安排
 * @author v-xyingde
 * @date 2023/6/14/10:31
 */
@RestController
@RequestMapping("exam")
@Slf4j
public class JwglExamController {

    private final TbJwglExamService  jwglExamService;

    private final TbJwglInfoService jwglInfoService;

    public JwglExamController(TbJwglExamService jwglExamService, TbJwglInfoService jwglInfoService) {
        this.jwglExamService = jwglExamService;
        this.jwglInfoService = jwglInfoService;
    }

    /**
     * 查询个人本学期考试安排
     * @param openId
     * @return
     */
    @GetMapping("getJwglMyExam")
    public ResponseMessage getJwglMyExam(@NotBlank(message = "用户标识不能为空") String openId) {
        return jwglExamService.getJwglMyExam(openId);
    }

    /**
     * 同步考试安排信息
     * @param examSynDto
     * @param request
     * @return
     */
    @RequestLimit(count = 3, time = 600000)
    @PostMapping("synMyExamData")
    public ResponseMessage synMyExamData(@Validated @RequestBody MyExamSynDto examSynDto, HttpServletRequest request) {
        // 先校验账号密码
        ThxyJwgl jwgl = jwglInfoService.checkJwglLogin(examSynDto.getOpenId(), request);
        return jwglExamService.synMyExamData(examSynDto, jwgl);
    }
}
